package com.example.lvsuo.controller;


import com.example.lvsuo.entity.RecordArchiveslibrary;
import com.example.lvsuo.entity.vo.RecordArchiveslibraryVo;
import com.example.lvsuo.entity.vo.RecordDocumentVo;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.IRecordArchiveslibraryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 档案/档案借阅 前端控制器
 * </p>
 *
 * @author 心心念念
 * @since 2021-03-30
 */
@RestController
@RequestMapping("/recordArchiveslibrary")
public class RecordArchiveslibraryController {
    @Autowired
    IRecordArchiveslibraryService iRecordArchiveslibraryService;

    /**
     * 高级查询+分页
     * @param recordArchiveslibraryVo
     * @return
     */
    @GetMapping
    public Result getRecordArchiveslibrary(RecordArchiveslibraryVo recordArchiveslibraryVo){
        PageHelper.startPage(recordArchiveslibraryVo.getPageId(),recordArchiveslibraryVo.getPageNum());
        PageInfo pageInfo = new PageInfo(iRecordArchiveslibraryService.getRecordArchiveslibrary(recordArchiveslibraryVo));
        return Result.back("ok","200",pageInfo);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping(params = "chaxun=1")
    public Result getRecordArchiveslibraryId(String id){
       List<RecordArchiveslibraryVo> list=iRecordArchiveslibraryService.getRecordArchiveslibraryId(id);
        System.out.println(list);
       return Result.back("ok","200",list);
    }

    /**
     * 添加
     * @param recordArchiveslibrary
     * @return
     */
    @PostMapping
    public Result insertRecordArchiveslibrary(@RequestBody RecordArchiveslibrary recordArchiveslibrary){

        iRecordArchiveslibraryService.insertRecordArchiveslibrary(recordArchiveslibrary);
        return Result.back("ok", "200");
    }

    /**
     * 修改
     * @param recordArchiveslibrary
     * @return
     */
    @PutMapping
    public Result updateRecordArchiveslibrary(@RequestBody RecordArchiveslibrary recordArchiveslibrary){
        iRecordArchiveslibraryService.updateById(recordArchiveslibrary);
        return Result.back("ok", "200");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteRecordArchiveslibrary(@PathVariable String id){
        iRecordArchiveslibraryService.deleteRecordArchiveslibrary(id);
        return Result.back("ok","200");
    }
}

